﻿using System.Diagnostics;

namespace NETCORE.WebApi.Client
{
    public class ClientService
    {
        static readonly HttpClient client = new HttpClient();


        public async Task<string> CallServiceByGet(string baseUrl, Dictionary<string, string> parameters)
        {
            // 构建完整的 URL，包括查询字符串参数
            var queryString = new FormUrlEncodedContent(parameters);
            var requestUri = new Uri(baseUrl + "?" + queryString.ReadAsStringAsync().Result);

            try
            {
                // 发送 GET 请求
                HttpResponseMessage response = await client.GetAsync(requestUri);

                // 确保请求成功
                response.EnsureSuccessStatusCode();

                // 读取响应内容
                string responseBody = await response.Content.ReadAsStringAsync();

                return responseBody;
            }
            catch (HttpRequestException e) { throw e; }


        }
    }
}
